<?php
include_once("../includes/page_utf_class.php");
//--------------------------------------------
if(!empty($_GET['deid']))
{
	$sql="delete from ".BRAND." where id='$_GET[deid]'";
	$re=$db->query($sql);
}

function update_custom_cat()
{
	global $db,$config;
	foreach($_POST['cid'] as $key=>$v)
	{
		if(!empty($_POST['del'][$key]))// is select del,will delete the item
		{
			$deid=$_POST['del'][$key];
			$sql="delete from ".BRAND." where id='$deid'";
			$re=$db->query($sql);
		}
		else
		{
			$_POST['nums'][$key]=empty($_POST['nums'][$key])?1:$_POST['nums'][$key];
			$_POST['statu'][$key]=empty($_POST['statu'][$key])?1:$_POST['statu'][$key];
			if(!empty($_POST['cid'][$key]))
			{
				$sql="update ".BRAND." set nums='".$_POST['nums'][$key]."',
				statu='".$_POST['statu'][$key]."' 
				where id='".$_POST['cid'][$key]."'";//update
				$ssql=NULL;
			}
			$db->query($sql);
		}
	}
}
if(!empty($_POST['submit']))
{
	update_custom_cat();
	admin_msg('module.php?m=brand&s=brand_list.php','操作成功');
}
$sql="select * from ".BRANDCAT." where pid='0' order by sort";
$db->query($sql);
$brandcat=$db->getRows();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<TITLE><?php echo lang_show('admin_system');?></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="main.js"></script>
</HEAD>
<body>
<div class="bigbox">
	<div class="bigboxhead"><?php echo lang_show('brand');?></div>
    <div class="bigboxbody">
		<form action="" method="get">
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="searh_left">品牌分类</td>
    <td width="*%">
      <select class="select" name="catid" id="catid">
	  <option value="0">全部</option>
	  <?php foreach($brandcat as $v){ ?>
	  <option <?php if($_GET['catid']==$v['id']){echo 'selected="selected"';}?> value="<?php echo $v['id'];?>"><?php echo $v['catname'];?></option>
	  <?php } ?>
	</select>
    </td>
  </tr>
  <tr>
    <td>关键词</td>
    <td><input class="text" value="<?php echo $_GET['keyword'];?>" name="keyword" type="text" id="keyword"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="Submit" value="提交">
	<input name="m" type="hidden" value="brand">
	<input name="s" type="hidden" value="brand_list.php">
	</td>
  </tr>
</table>
	</form>

 <form action="" method="post" enctype="multipart/form-data">
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="theader">
    <td width="41"><?php echo lang_show('delete');?></td>
    <td width="28"><?php echo lang_show('nums');?></td>
    <td width="325"><?php echo lang_show('name');?></td>
    <td width="191"><?php echo lang_show('company');?></td>
	<td width="186"><?php echo lang_show('tel');?></td>
    <td width="137">品牌类别</td>
    <td width="92" align="center" valign="middle">操作</td>
  </tr>
  <?php
	$i=0;$sql=NULL;
	if(!empty($_GET['catid']))
		$sql.=" and b.catid='$_GET[catid]' ";
	if(!empty($_GET['keyword']))
		$sql.=" and b.name like '%$_GET[keyword]%' ";
	$sql="select b.*,c.catname from ".BRAND." b left join ".BRANDCAT." c on c.id=b.catid where 1 $sql order by b.nums asc ";
	//=============================
	$page = new Page;
	$page->listRows=20;
	if (!$page->__get('totalRows')){
		$db->query($sql);
		$page->totalRows = $db->num_rows();
	}
	$sql .= "  limit ".$page->firstRow.",20";
	$pages = $page->prompt();
	//=====================
	$db->query($sql);
	$re=$db->getRows();
	foreach($re as $v)
	{
  ?>
  <tr >
    <td>
	<input type="hidden" name="cid[]" value="<?php echo $v['id'];?>">
	<input type="checkbox" name="del[]" value="<?php echo $v['id'];?>" ></td>
    <td><input name="nums[]" type="text" size="3" value="<?php echo $v['nums'];?>"></td>
    <td><?php 
		if(!empty($v["pic"])) 
			echo '<img height=50 src="'.$v["pic"].'" >';
        ?>
      <br />
      <a target="_blank" href="../?m=brand&s=content&id=<?php echo $v['id'];?>"><?php echo $v['name'];?></a></td>
    <td><?php echo $v['company'];?>&nbsp;</td>
	<td>&nbsp;<?php echo $v['tel'];?></td>
    <td><?php echo $v['catname'];?></td>
    <td>
    <a href="module.php?m=brand&s=add_brand.php&id=<?php echo $v['id'];?>"><?php echo $editimg;?></a>
	<a href="module.php?m=brand&s=brand_list.php&deid=<?php echo $v['id'];?>"><?php echo $delimg;?></a>
	<a href="module.php?m=brand&s=add_brand_user.php&id=<?php echo $v['id'];?>">代理商</a>	</td>
  </tr>
  <?php $i++; }?>
  <tr>
    <td colspan="8"><input class="btn" type="submit" name="submit" id="button" value="<?php echo lang_show('submit');?>">      <div class="page"><?php echo $pages;?></div></td>
    </tr>
</table>
</form>
</div>
</div>
</body>
</html>